﻿// javascript for admin page
jQuery(document).ready(function () {
    // enable tooltip
    vtip();

    // toggle admin dropdown menu
    $("#a-systembar li").click(function () {
        $(this).find("ul").toggle();
    }).hover(null, function () {
        $(this).find("ul").css("display", "none");
    });

    // confirmation on logout
    $("#a-systembar .a-logout a").click(function () {
        if (!confirm('Are you sure you want to logout?'))
            return false;
    });

    // on/off switch toggle
    // init state
    $("input[type='checkbox']").each(function () {
        if ($(this).attr("checked"))
            $(this).siblings(".a-on").addClass("a-active");
        else
            $(this).siblings(".a-off").addClass("a-active");
    });
    $(".a-on").click(function () {
        $(this).addClass("a-active");
        $(this).siblings(".a-off").removeClass("a-active");
        $(this).siblings("input[type='checkbox']").attr("checked", "checked");
    });
    $(".a-off").click(function () {
        $(this).addClass("a-active");
        $(this).siblings(".a-on").removeClass("a-active");
        $(this).siblings("input[type='checkbox']").removeAttr("checked");
    });

    /*
    * Active Menu jQuery Plugin 1.0.0
    *
    * Copyright (c) 2009 Chad Ort
    * http://www.caodesigns.com/blog/free-stuff/jquery-active-menu-plugin-2.php?postID=39
    * editted by Hoang for KillDaBugs
    */
    $.fn.activeMenu = function (activeClass) {
        var loc = location.href;
        $(this).find('a').each(function () {
            var href = $(this).attr('href');
            if (loc.search(href) != -1) {
                $(this).parent().addClass(activeClass);
                $(this).parent('li').parent('ul').parent('li').addClass(activeClass);
                return;
            }
        });
    }

    // active current item in navigations
    // top menu
    $("#a-navigation").activeMenu('active');
    // sidebar menu
    $("#a-subnavigation").activeMenu('active');
});